<?php
namespace Home\Service;

use Think\Service\BasicService;

class YZGoodsService extends BasicService {
    public function insert($model) {
        return $this->db->add($model);
    }

    public function remove($condition) {
        return $this->db->where($condition)->delete();
    }

    public function update($model) {
        return $this->db->save($model);
    }

    public function find($condition) {
        return $this->db->where($condition)->find();
    }

    public function querySQL($sql){
        $Model = M();
        return $Model->query($sql);
    }

    public function query($condition,$field=null,$order ='created_time desc') {
        $data =  $this->db->field($field)->where($condition)
            ->order($order)->select();
        return $data;
    }

    public function AddAll($model){
        $this->db->startTrans();
        $DELOK = $this->db->where('1')->delete();
        if($DELOK){
            foreach($model as $k =>$v){
                $ADDOK =  $this->db->addAll($v);
                if(!$ADDOK){
                    $this->db->rollback();
                    return 0;
                }
                sleep(1);
            }
            $this->db->commit();
            return 1;

        }else{
            $this->db->rollback();
            return 0;
        }


    }

}

?>